package com.shop2cn.iapi.sqoptrade.parameter.req;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

@SuppressWarnings("serial")
public class PlaceOrderByApportionedAmountReq extends PlaceOrderReq {

	public PlaceOrderByApportionedAmountReq() {
		
		this.setAppId("autotest");
	}
	
	public static <T> void fatherToChild(T father, T child) throws Exception {
		
		if (child.getClass().getSuperclass() != father.getClass()) {
			throw new Exception("child 不是 father 的子类");
		}
		
		Class<?> fatherClass = father.getClass();
		Field[] declaredFields = fatherClass.getDeclaredFields();
		
		for (int i = 0; i < declaredFields.length; i++) {
			
			Field field = declaredFields[i];
			Method method = null;
			
			if (field.getType() == boolean.class) {
				
				method = fatherClass.getDeclaredMethod("is"
						+ upperHeadChar(field.getName()));
			} else {
				
				method = fatherClass.getDeclaredMethod("get"
						+ upperHeadChar(field.getName()));
			}
			
			Object obj = method.invoke(father);
			field.setAccessible(true);
			field.set(child, obj);
		}
	}
	
	public static String upperHeadChar(String in) {
        String head = in.substring(0, 1);
        String out = head.toUpperCase() + in.substring(1, in.length());
        return out;
    }
}
